package com.chai.job;

import com.chai.constant.RedisConstant;
import com.chai.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Set;

public class ClearImgJob {

    @Autowired
    JedisPool jedisPool;

    public void clearImg(){
        Set<String> imgNameList = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES,RedisConstant.SETMEAL_PIC_DB_RESOURCES);
            if (imgNameList!=null && imgNameList.size()>0){
                for (String imgName : imgNameList) {
                    System.out.println("清理垃圾图片 —— imgName = " + imgName);
                    QiniuUtils.deleteFileFromQiniu(imgName);
                    jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES,imgName);
                }
            }
    }
}
